﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.JuShuiTan.Model;
using SHKF.B2C.JuShuiTan.Model.Inter.InventoryV2;
using SHKF.B2C.JuShuiTan.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.JuShuiTan.Service.Controllers
{
    /// <summary>
    /// 盘点
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class InventoryController : BaseController
    {
   
        public InventoryController(IServiceProvider serviceProvider, ILogger<OrderController> logger) :base(serviceProvider,logger)
        {
            
        }

        /// <summary>
        /// 新建盘点单
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost("upload")]
        public async Task<InventoryUploadDto> upload(InventoryUploadParam data)
        {
            InventoryUploadDto dto;

            BaseDto dto2 = this.GetCompanyID(); 
            if( dto2.code == -1)
            {
                dto = new InventoryUploadDto();
                dto.code = -1;
                dto.msg = dto2.msg;

                return dto;
            }
            else
            {
                this.httpClient.CompanyID = dto2.msg; 
            }
             
            try
            {
                dto = await this.httpClient.InventoryvUpload(data);
            }
            catch (Exception ex)
            {
                dto = new InventoryUploadDto();
                dto.code = -1;
                dto.msg = ex.Message; 
            }

            return dto;
        }
    }
}
